
<script>
	
	function cancel(){
		window.close();		
	}
	function save(){
		$("#frmData").attr("action","index.php?r=keuangan/tu/monthly_fee/editGenerateMF");
		$("#frmData").attr("target","_self");
		$("#frmData").submit();		
		
	}
	function changePeriod(){
		intvPeriod = getIntervalPeriod($("#start_period").val(),$("#end_period").val());
		$("#ttl_monthly_fee").val($("#mf").val() * intvPeriod);
		$("#ttl_disc_fee").val($("#disc_mf").val() * intvPeriod);
		refreshDisplayCurrency();
	}
	
	$(function(){
		var student_class_src =[];
		<?php
			foreach ($arrStudentClass as $studentClass){
				$arrData = "{
					label:'".$studentClass->student->sid." - ".$studentClass->student->name."',
					value:'".$studentClass->student->sid." - ".$studentClass->student->name."',
					id:'".$studentClass->id."',
					monthly_fee:".$studentClass->monthly_fee.",
					disc_monthly_fee:".$studentClass->disc_monthly_fee. ",
					tingkatan_name:'".$studentClass->kelasTahunAjaran->kelas->tingkatan->name. "',
					kelas_name:'".$studentClass->kelasTahunAjaran->kelas->name. "'}";	
		
				echo "student_class_src.push($arrData);";
			} 
		?>
		$("#student_name").autocomplete({
			source:student_class_src,
			change:function(event,ui){
				if (ui.item == null){
					alert("Invalid Value !");
					$("#student_class_id").val("");
					$("#student_name").focus();
				}else{
					console.log(ui.item);
					intvPeriod = getIntervalPeriod($("#start_period").val(),$("#end_period").val());
					
					$("#student_class_id").val(ui.item.id);
					$("#mf").val(ui.item.monthly_fee);
					$("#disc_mf").val(ui.item.disc_monthly_fee);
					$("#ttl_monthly_fee").val(ui.item.monthly_fee * intvPeriod);
					$("#ttl_disc_fee").val(ui.item.disc_monthly_fee * intvPeriod);					
					refreshDisplayCurrency();
					$("#tingkatan_name").html(ui.item.tingkatan_name);
					$("#kelas_name").html(ui.item.kelas_name);
				}
			},
			
		});
		refreshDisplayCurrency();
		$('#start_period,#end_period').monthpicker({
			pattern: 'yyyy-mm',
		});
		
	});
	
</script>

<div style="border-bottom:2px solid #000;padding-bottom:5px;margin-bottom:20px">
<?php 
	$this->widget('application.components.widgets.ActionBar', 
		array("menuAlign" => "right", 
			'items' => array(
				array(
					'id' => "btnSave",
					'title' => "Simpan",
					'icon' => "images/action/Actions-document-save-all-icon.png",
					'callback'=>"save",
					'hidden'=> ($ttl_paid + $ttl_cn) == 0 ? false : true, 
				),					
				array(
					'id' => "btnCancel",
					'title' => "Batal",
					'icon' => "images/action/Actions-dialog-cancel-icon.png",
					'callback'=>"cancel"
				),
			)
		)
	);
?>
</div>

<form id="frmData" action="index.php?r=keuangan/tu/monthly_fee/editGenerateMF" method="POST">		
	<input type="hidden" name="id" id="id" value="<?php echo $id;?>" readonly/>
	<input type="hidden" name="op" id="op" value="<?php echo $op;?>" readonly/>
	
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Departemen")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<label class="form mandatory" style=""><?php echo $department_id ?></label>				 
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Mulai")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<input type="text" id="start_period" name="start_period" style="width:100px" value="<?php echo $start_period; ?>" onChange="changePeriod()" />			
		<label class="form mandatory" style="margin-left:10px;margin-right:10px"><?php echo Yii::t("label","Sampai :")?></label>
		<input type="text" id="end_period" name="end_period" style="width:100px" value="<?php echo $end_period; ?>" onChange="changePeriod()" />		
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Student")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<?php
			$lock = $op =="edit"?"readonly":""; 
		?>
		<input type="text" id="student_name" name="student_name" style="width:300px" value='<?php echo $student_name ?>' <?php echo $lock; ?> />
		<input type="hidden" id="student_class_id" name="student_class_id" value="<?php echo $student_class_id;?>" style="width:20px" />
		<input type="hidden" id="mf" style="width:20px" value="<?php echo $monthly_fee;?>" />
		<input type="hidden" id="disc_mf" style="width:20px" value="<?php echo $disc_monthly_fee;?>" />
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Tingkatan")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<label class="form mandatory" style="" id="tingkatan_name"><?php echo $tingkatan_name;?></label>				 
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Kelas")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<label class="form mandatory" style="" id="kelas_name"><?php echo $kelas_name;?></label>				 
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Payment Type")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<select name="payment_type" id="payment_type">
			<?php
				$selected =  $payment_type == "BCA VA" ? "selected" :"";  
			?>
			<option value="BCA VA" <?php echo $selected;?> >BCA Virtual Account</option>
			<?php
				$selected =  $payment_type == "CASH" ? "selected" :"";  
			?>
			<option value="CASH" <?php echo $selected;?> >Cash</option>
		</select>		
	</div>
	
		
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Total Monthly Fee")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<input class="currency" type="text" id="ttl_monthly_fee" name="ttl_monthly_fee" style="width:100px" value="<?php echo $ttl_monthly_fee; ?>" />		
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Total Late Fee")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<input class="currency" type="text" id="ttl_late_fee" name="ttl_late_fee" style="width:100px" value="<?php echo $ttl_late_fee; ?>" />		
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Total Discount")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<input class="currency" type="text" id="ttl_disc_fee" name="ttl_disc_fee" style="width:100px" value="<?php echo $ttl_disc_fee; ?>" />		
	</div>
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label","Total Paid")?></label>
		<label class="form mandatory" style="width:10px">:</label>
		<input class="currency" type="text" id="ttl_paid" name="ttl_paid" style="width:100px" value="<?php echo $ttl_paid; ?>" disabled />		
	</div>
	
	
</form>

